<template>
    <van-form @submit="onSubmit">
    <van-cell-group inset>
      <van-field
        v-model="use.secret_answer"
        name="secret_answer"
        label="密保"
        placeholder="密保"
        :rules="[{ required: true, message: '请填写密保' }]"
      />
      <van-field
        v-model="use.password"
        type="password"
        name="password"
        label="新密码"
        placeholder="新密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
    </van-cell-group>
    <div style="margin: 16px;">
      <van-button round block type="primary" native-type="submit">
        提交
      </van-button>
    </div>
  </van-form>
  </template>
  
  <script setup> 
  import { ref } from 'vue';
  import {PasswordReset} from '@/api/user'
  import { showConfirmDialog, showSuccessToast } from "vant";
  import {useRouter} from "vue-router"
  import { removeToken } from "@/utils/token";
  
  let router=useRouter()
  let use=ref({
    secret_answer:'',
    password:'',
  })
  console.log(use);
  let onSubmit= (data)=>{
    showConfirmDialog({
      title: "确认修改密码",
      message: "是否确认修改密码",
    })
      .then(async () => {
        console.log(data);
        // 确定 执行修改更新数据
        await PasswordReset(data)
        //清除token
        removeToken();
        showSuccessToast("已经修改密码");
        router.replace("/login");
      })
      .catch(() => {
      });
  }
  </script>